<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<p class="name">

</p>

<body>
  <div></div>
  <script>
    const gift = '50g的茶叶,清洗球'
    // 1. 把字符串拆分为数组
    const giftArr = gift.split(",");
    // 2. 根据数组元素的个数，生成 对应 span标签
    console.log(giftArr);
    // giftArr.map(item => {
    //   return `<span>【赠品】` + item + `</span>`
    // // })
    // giftArr.map(item => `<span>【赠品】` + item + `</span>`);
    // gift.split(",").map(item => `<span>【赠品】` + item + `</span>`).join(",");
    // document.querySelector(".name").innerHTML = gift.split(",").map(item => `<span>【赠品】` + item + `</span></br>`).join(
    //   "");
    document.querySelector(".name").innerHTML = gift.split(",").map(item => `<span>【赠品】${item }</span></br>`).join(
      "");
  </script>
</body>

</html>